﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.DomainObject.Technology;
using WMS.FC.Domain.Repository;
using WMS.FC.Domain.Service.System;
using WMS.FC.Domain.Service.Technology.Interface;

namespace WMS.FC.Domain.Service.Technology
{
    public class GetTechnologyRouteProcessListService : ServiceBase, IGetTechnologyRouteProcessListService
    {
        protected readonly ITechnologyRepository technologyRepository;

        public GetTechnologyRouteProcessListService(
            ILogger<ServiceBase> logger,
            IOptions<WmsSettings> options,
            IMapper mapper,
            ITechnologyRepository technologyRepository)
            : base(logger, options, mapper)
        {
            this.technologyRepository = technologyRepository;
        }

        public async Task<ActionResult<List<TechnologyRouteProcessDO>>> GetTechnologyRouteProcessList(string? technologyRouteCode, UserInfo userInfo)
        {
            var result = new ActionResult<List<TechnologyRouteProcessDO>>("获取工艺路径工序列表");
            try
            {
                if (string.IsNullOrWhiteSpace(technologyRouteCode))
                    return result.ArgumentError("工艺路径编码不能为空");

                var technologyRouteProcessPOList = await technologyRepository.GetTechnologyRouteProcessList(technologyRouteCode);
                result.Data = mapper.Map<List<TechnologyRouteProcessDO>>(technologyRouteProcessPOList);
            }
            catch (Exception ex)
            {
                return result.Exception(ex);
            }

            return result;
        }
    }
}
